package com.ruoyi.boat.service.impl;

import com.ruoyi.boat.domain.DeviceBoat;
import com.ruoyi.boat.mapper.DeviceBoatMapper;
import com.ruoyi.boat.service.IDeviceBoatService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 设备艇关系Service业务层处理
 *
 * @author ruoyi
 * @date 2023-08-02
 */
@Service
public class DeviceBoatServiceImpl implements IDeviceBoatService {
    @Autowired
    private DeviceBoatMapper deviceBoatMapper;

    /**
     * 查询设备艇关系
     *
     * @param deviceId 设备艇关系主键
     * @return 设备艇关系
     */
    @Override
    public DeviceBoat selectDeviceBoatByDeviceId(Long deviceId) {
        return deviceBoatMapper.selectDeviceBoatByDeviceId(deviceId);
    }

    /**
     * 查询设备艇关系列表
     *
     * @param deviceBoat 设备艇关系
     * @return 设备艇关系
     */
    @Override
    public List<DeviceBoat> selectDeviceBoatList(DeviceBoat deviceBoat) {
        return deviceBoatMapper.selectDeviceBoatList(deviceBoat);
    }

    @Override
    public List<Long> selectDeviceIdListByBoatId(Long boatId) {
        return selectDeviceBoatList(new DeviceBoat().setBoatId(boatId)).stream().map(DeviceBoat::getDeviceId).collect(Collectors.toList());
    }

    /**
     * 新增设备艇关系
     *
     * @param deviceBoat 设备艇关系
     * @return 结果
     */
    @Override
    public int insertDeviceBoat(DeviceBoat deviceBoat) {
        return deviceBoatMapper.insertDeviceBoat(deviceBoat);
    }

    /**
     * 修改设备艇关系
     *
     * @param deviceBoat 设备艇关系
     * @return 结果
     */
    @Override
    public int updateDeviceBoat(DeviceBoat deviceBoat) {
        return deviceBoatMapper.updateDeviceBoat(deviceBoat);
    }

    /**
     * 批量删除设备艇关系
     *
     * @param deviceIds 需要删除的设备艇关系主键
     * @return 结果
     */
    @Override
    public int deleteDeviceBoatByDeviceIds(String deviceIds) {
        return deviceBoatMapper.deleteDeviceBoatByDeviceIds(Convert.toStrArray(deviceIds));
    }

    /**
     * 删除设备艇关系信息
     *
     * @param deviceId 设备艇关系主键
     * @return 结果
     */
    @Override
    public int deleteDeviceBoatByDeviceId(Long deviceId) {
        return deviceBoatMapper.deleteDeviceBoatByDeviceId(deviceId);
    }


    /**
     * 删除设备艇关系信息
     *
     * @param boatId 设备艇关系主键
     * @return 结果
     */
    @Override
    public int deleteDeviceBoatByBoatId(Long boatId) {
        return deviceBoatMapper.deleteDeviceBoatByBoatId(boatId);
    }
}
